package main

import "fmt"

func minArray2(numbers []int) int {
	left := 0
	right := len(numbers) - 1
	for left < right {
		mid := left + (right-left)>>1
		if numbers[mid] > numbers[right] {
			left = mid + 1
		} else if numbers[mid] <= numbers[right] {
			right = right - 1
		}
	}
	return numbers[left]
}

// {3,6,9,7,2,5,9}
// 0 3 7
// 0 1 3
func minArray(numbers []int) int {
	low := 0
	high := len(numbers) - 1
	for low < high {
		pivot := low + (high-low)/2
		if numbers[pivot] < numbers[high] {
			high = pivot
		} else if numbers[pivot] > numbers[high] {
			low = pivot + 1
		} else {
			high--
		}
	}
	return numbers[low]

}

func main() {
	var list = []int{5, 6, 7, 8, 9, 2, 3, 4}
	fmt.Println(minArray(list))

	//fmt.Println(7/2)
}
